package Client.GUI;

import java.util.ArrayList;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import Server.DataBase.SubmittedTask;

public class SubmitedTaskModel extends AbstractTableModel{
    /**
     * 
     */
	private static final long serialVersionUID = 1L;

    Vector<String[]> cache; // will hold String[] objects . . .

    int colCount=4;

    String[] headers = {"Last Name", "First Name", "File Name", "On Time"};

    public SubmitedTaskModel() {
            cache = new Vector<String[]>();
    }

    public String getColumnName(int i) {
            return headers[i];
    }

    public int getColumnCount() {
            return colCount;
    }

    public int getRowCount() {
            return cache.size();
    }

    public Object getValueAt(int row, int col) {
            return ((String[]) cache.elementAt(row))[col];
    }

    public void setValueAt(int row, int col, String msg){
      ((String[]) cache.elementAt(row))[col] = msg;
      fireTableChanged(null);
    }

    public void setArray(ArrayList<SubmittedTask> array){
      cache.removeAllElements();
      for (int i=0; i<array.size(); i++) addToArray(array.get(i));
      fireTableChanged(null);
    }

    public void addToArray(SubmittedTask task){
      String[] record = new String[colCount];
      record[0] = task.getStudent().getLastName();
      record[1] = task.getStudent().getFirstName();
      record[2] = task.getFileName();
      String str;
      if (task.getOntime()==1) str="Yes";
      else str = "No";
      record[3] = str;
      cache.addElement(record);
    }
}
